﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Topshelf;

namespace EasyNet.Componets.Task.ConsoleHost
{
    class Program
    {
        static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

            var unityDependencyResolver = new EasyNet.Componets.IoC.Unity.UnityDependencyResolver();
            var container = unityDependencyResolver.UnityContainer;
            EasyNet.Componets.Core.Inject.IoC.Initialize(unityDependencyResolver);


            HostFactory.Run(x =>
            {
                x.Service<QuartzServer>(s =>
                {
                    s.ConstructUsing(name => QuartzServerFactory.CreateServer());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });
                x.RunAsLocalSystem();

                x.SetDescription(Configuration.ServiceDescription);
                x.SetDisplayName(Configuration.ServiceDisplayName);
                x.SetServiceName(Configuration.ServiceName);
            });

            if (container != null)
            {
                container.Dispose();
            }
        }
    }
}
